<template>
    <div class="experienceTable">
        <div class="experience_inputs">
            <div class="operate_inputs">
                <el-form :inline="true" :model="formInline" class="demo-form-inline">
                    <el-select class='newWidth' v-if='xxSelect' v-model="formInline.agentid" filterable placeholder="学校">
                        <el-option
                             v-for="(school,b) in schoolList"
                            :key="b"
                            :label="school.company +'('+ school.nickname + ')'"
                            :value="school.userid">
                        </el-option>
                    </el-select>
                    <el-select class='newWidth' v-model="formInline.classid" filterable placeholder="班级">
                        <el-option
                            v-for="(item,a) in classList"
                            :key="a"
                            :label='item.name'
                            :value="item.id">
                        </el-option>
                    </el-select>
                    <el-select class='newWidth' v-model="formInline.teacherid" filterable placeholder="外教">
                        <el-option
                            v-for="(teacher,i) in teacherList"
                            :key="i"
                            :label="teacher.teachername"
                            :value="teacher.id">
                        </el-option>
                    </el-select>
                    <el-form-item label="上课时间:">
                        <el-date-picker
                            v-model="formInline.start_time"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择开始日期" style="width:160px;">
                        </el-date-picker>
                        <el-date-picker
                            v-model="formInline.end_time"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择结束日期" style="width:160px;">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button class="search_btn" type="primary" @click="getTableList"><i class="el-icon-search"></i>查询</el-button>
                        <el-button class="reset_btn" type="primary" @click="clearSearch"><i class="el-icon-refresh"></i>清空查询</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <el-table
            v-loading="loading2"
            element-loading-text="加载中..."
            :data="experienceData"
            stripe 
            size="mini"
            border resizable
            style="width: 100%"
            :height="tableHeight">
            <el-table-column label="课程ID" :align="align">
                <template slot-scope="scope">{{scope.row.courseid}} </template>
            </el-table-column>
            <el-table-column label="学校" :align="align">
                <template slot-scope="scope">{{scope.row._school_name}} </template>
            </el-table-column>
            <el-table-column label="班级" :align="align">
                <template slot-scope="scope">{{scope.row.class.name}} </template>
            </el-table-column>
            <el-table-column label="助教" :align="align">
                <template slot-scope="scope">{{scope.row._assistant_name}} </template>
            </el-table-column>
            <el-table-column label="上课时间" :align="align">
                <template slot-scope="scope">{{scope.row.classSchedule.starttime | transData}} </template>
            </el-table-column>
            <el-table-column label="外教" :align="align">
                <template slot-scope="scope">{{scope.row.snap.teachernick}} </template>
            </el-table-column> 
            <el-table-column label="教材" :align="align">
                <template slot-scope="scope">{{scope.row.snap.coursewarename}} </template>
            </el-table-column>
            <el-table-column label="课程性质" :align="align">
                <template slot-scope="scope">{{scope.row.classSchedule.classtype==1?'体验班':'正式班'}} </template>
            </el-table-column>   
            <el-table-column 
                align="center"
                min-width="390"
                label="操作">
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        @click='getCourseInfo(scope.row.grouporderid)'>课程详情</el-button>
                    <el-button
                        size="mini"
                        v-if="scope.row.cancelCourse==1?true:false"
                        @click='cancelCourse(scope.row.grouporderid)'>取消课程</el-button>
                    <el-button
                        size="mini"
                        v-if="scope.row.changeCourse==1?true:false"
                        @click='changeCourse(scope.row.grouporderid,scope.row.class.id)'>改签课程</el-button>
                    <el-button
                        size="mini"
                        v-if="scope.row.changeCourseware==1?true:false"
                        @click='changeCourseWare(scope.row.grouporderid)'>改签教材</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="page_block">
            <el-pagination
                background
                @current-change="handleCurrentChange"
                :current-page.sync="currentPage"
                :page-size="page_size"
                small
                layout="prev, pager, next, jumper"
                :total="totalCount">
            </el-pagination>
        </div>
        <!-- 取消课程 -->
        <el-dialog title="取消课程" 
            width='40%'
            :modal=false
            :close-on-click-modal=false
            :visible.sync="dialogFormVisible1">
            <div>
                此时距开课{{cancleInfo.diffhour}}小时，继续操作将扣取{{cancleInfo.chargepercent}}课时费，共计{{cancleInfo.chargemoney}}元，确认操作？
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button class="dialog_close" @click="dialogFormVisible1=false">取 消</el-button>
                <el-button class="dialog_confirm" type="primary" @click="confirmCancel">确 定</el-button>
            </div>
        </el-dialog>

        <!-- 课程详情 -->
        <!-- v-if='ifcourseInfo' -->
        <el-dialog title="课程详情" 
            width='40%'
            :modal=false
            v-if='ifcourseInfo'
            :visible.sync="dialogFormVisible4">
            <el-form>
                <el-form-item label="课程编号:" :label-width="formLabelWidth4">
                    <div>{{courseInfo.classSchedule.classid}}</div>
                </el-form-item>
                <el-form-item label="课程类项:" :label-width="formLabelWidth4">
                    <div v-if='courseInfo.class'>{{courseInfo.class.classtype==1?'First Class':'Regular Class'}}</div>
                </el-form-item>
                <el-form-item label="课程规模:" :label-width="formLabelWidth4">
                    <div>班课</div>
                </el-form-item>
                <el-form-item label="上课班级:" :label-width="formLabelWidth4">
                    <div v-if='courseInfo.class'>{{courseInfo.class.name}}</div>
                </el-form-item>
                <el-form-item label="所属合作校:" :label-width="formLabelWidth4">
                    <div>{{courseInfo._school_name}}</div>
                </el-form-item>
                <el-form-item label="合作校联系方式:" :label-width="formLabelWidth4">
                    <div>{{courseInfo.school.mobile}}</div>
                </el-form-item>
                <el-form-item label="云海螺负责人:" :label-width="formLabelWidth4">
                    <div v-if='courseInfo.school.admin'>{{courseInfo.school.admin.realname}}</div>
                </el-form-item>
                 <el-form-item label="负责人联系方式:" :label-width="formLabelWidth4">
                    <div v-if='courseInfo.school.admin'>{{courseInfo.school.admin.mobile}}</div> 
                </el-form-item>
                <el-form-item label="上课时间:" :label-width="formLabelWidth4">
                    <el-input disabled v-model="starttime" class='divided_150'></el-input> -
                    <el-input disabled v-model="endtime" class='divided_150'></el-input>
                </el-form-item>
                <el-form-item label="老师姓名:" :label-width="formLabelWidth4">
                    <el-input disabled v-model="courseInfo.teacher.teachername"></el-input>
                </el-form-item>
                 <el-form-item label="学生上课工具:" :label-width="formLabelWidth4">
                    <div style="float:left;">{{courseInfo._classtoolName}} ：{{courseInfo.classtoolaccount}}</div>
                    <el-button type="danger" v-if='courseInfo.changeTool==1?true:false'  @click="changeClassTool" plain style="float:right;">改签上课工具</el-button>
                </el-form-item>
                <el-form-item label="老师上课工具:" :label-width="formLabelWidth4">
                    <!-- <el-input disabled v-model="courseInfo.teacher.skype"></el-input> -->
                    <div>{{courseInfo._classtoolName}} ：{{courseInfo._teacherToolAccount}}</div>
                </el-form-item>
                <el-form-item label="课件名称:" :label-width="formLabelWidth4">
                    <div>{{courseNameTree}}</div>
                </el-form-item>
                <el-form-item label="学员课件下载:" :label-width="formLabelWidth4">
                    <div  v-if='courseInfo.bookData'
                        class="kejianStyle"
                        v-for="(book,index) in courseInfo.bookData.stu_book_b" :key="index">
                        <el-button icon='el-icon-document' plain size='mini'                      
                        @click="dodown(book)"></el-button>
                    </div>
                </el-form-item>
                <el-form-item label="老师课件下载:" :label-width="formLabelWidth4">
                    <div v-if='courseInfo.bookData' 
                        class="kejianStyle"
                        v-for="(tbookb,index2) in courseInfo.bookData.teacher_book_b" :key='index2'>
                        <el-button icon='el-icon-document' plain size='mini'                        
                        @click="dodown(tbookb)"></el-button>
                    </div>
                </el-form-item>
                <el-form-item label="双师中教教案:" :label-width="formLabelWidth4">
                    <div v-if='courseInfo.bookData' 
                        class="kejianStyle"
                        v-for="(ctbook,index3) in courseInfo.bookData.coteacher_book" :key='index3'>
                        <el-button icon='el-icon-document' plain size='mini'                        
                        @click="dodown(ctbook)"></el-button>
                    </div>
                </el-form-item>
                <el-form-item label="音频课件下载:" :label-width="formLabelWidth4">
                    <div v-if='courseInfo.bookData' 
                        class="kejianStyle"
                        v-for="(sbooka,index4) in courseInfo.bookData.stu_book_audio" :key='index4'>
                        <el-button icon='el-icon-document' plain size='mini'                        
                        @click="dodown(sbooka)"></el-button>
                    </div>
                </el-form-item>
                <el-form-item label="老师对这节课的评价:" :label-width="formLabelWidth4">
                    <el-input
                        type="textarea"
                        :rows="5" disabled
                        placeholder="请输入内容"
                        v-if='courseInfo.teacherCourseEvel'
                        v-model="courseInfo.teacherCourseEvel.content">
                    </el-input>
                </el-form-item>
                <el-form-item label="老师对这节课学员的评价" :label-width="formLabelWidth4">
                </el-form-item>
                <div v-for='(item2,index2) in courseInfo.agentCourserEvel' :key='index2'>
                    <el-form-item :label="item2.nickname+':'" :label-width="formLabelWidth4">
                        <el-input
                            type="textarea"
                            :rows="5" disabled
                            placeholder="请输入内容"
                            v-model="item2.teachereval">
                        </el-input>
                    </el-form-item>
                </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button class="dialog_close" @click="dialogFormVisible4=false">关闭</el-button>
            </div>
        </el-dialog>

        <!-- 改签课程 -->
        <el-dialog title="改签课程" 
            width='30%'
            :close-on-click-modal=false
            :modal=false
            :visible.sync="dialogFormVisible2">
            <el-form :model="form">
                 <el-form-item label="课程类别:" :label-width="formLabelWidth">
                    <el-radio-group>
                         <el-radio :label='orderInfo?orderInfo.coursetype.itemid:""'>{{orderInfo?orderInfo.coursetype.name:''}}</el-radio> 
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="课程教材:" :label-width="formLabelWidth">
                    <el-select class="divided_200" v-model="course1id" @change="course1Change" placeholder="第一级">
                        <el-option 
                            v-for="(c1,f) in course1"
                            :key="f" :label="c1.title" :value="c1.id"></el-option>
                    </el-select>
                    <el-select class="divided_200" v-if='c2show' v-model="form.coursewareid" @change="course2Change" placeholder="第二级">
                        <el-option 
                            v-for="(c2,s) in course2"
                            :key="s" :label="c2.title" :value="c2.id"></el-option>
                    </el-select>
                    <el-select class="divided_200" v-if="c3show" v-model="course3id" placeholder="第三级">
                         <el-option 
                            v-for="(c3,t) in course3"
                            :key="t" :label="c3.title" :value="c2.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="上课时间：" :label-width="formLabelWidth">
                    <el-date-picker 
                        type="datetime" 
                        placeholder="选择日期" 
                        value-format="yyyy-MM-dd HH:mm:ss"
                        v-model="form.startdate" 
                        style="width: 180px;"></el-date-picker>
                    <el-date-picker 
                        type="datetime" 
                        placeholder="选择日期" 
                        value-format="yyyy-MM-dd HH:mm:ss"
                        v-model="form.enddate" 
                        style="width: 180px;"></el-date-picker>
                </el-form-item>
                
                <!-- <el-form-item label="性别要求：" :label-width="formLabelWidth">
                    <el-radio-group v-model="form.gender">
                        <el-radio label='0'>无需求</el-radio>
                        <el-radio label='1'>男</el-radio>
                        <el-radio label='2'>女</el-radio>
                    </el-radio-group>
                </el-form-item> -->
                <el-form-item label="上课具体要求：" :label-width="formLabelWidth">
                    <el-radio-group v-model="form.classtool">
                        <el-radio v-for="(tool,gj) in form.classTool" :key='gj' 
                        :label="tool.attriid">{{tool.attriname}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                 <!-- <el-form-item label="中文要求：" :label-width="formLabelWidth">
                    <el-radio-group v-model="form.chineselevel">
                         <el-radio v-for="(clevel,zw) in chineselevel" :key='zw' 
                        :label="clevel.attriid">{{clevel.attriname}}</el-radio>
                    </el-radio-group>
                </el-form-item>  -->
                <el-form-item label="老师区域：" :label-width="formLabelWidth">
                    <el-radio-group v-model="form.areaid">
                        <el-radio :label='orderInfo?orderInfo.areainfo.itemid:""'>{{orderInfo?orderInfo.areainfo.name:''}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label-width="260px">
                    <el-button class="search_btn" @click="searchTeacher"><i class="el-icon-search"></i>查询</el-button>
                </el-form-item>
            </el-form>

            <teacherCard @changeDia='dialogChange' :availableTeacher='availableTeacher' :form='form'></teacherCard>
            <div slot="footer" class="dialog-footer">
                <el-button class="dialog_close" @click="dialogFormVisible2=false">取 消</el-button>
                <el-button class="dialog_confirm" type="primary" @click="dialogFormVisible2=false">确 定</el-button>
            </div>
        </el-dialog>

        <!-- 改签教材 -->
        <el-dialog title="改签教材" 
            width='40%'
            :modal=false
            :close-on-click-modal=false
            :visible.sync="dialogFormVisible3">
            <el-form>
                <el-form-item label="学习计划：" :label-width="formLabelWidth">
                    <el-cascader
                        :options="options"
                        v-model="selectedOptions"
                        @change="cascaderChange"
                        size='Maximum'>
                    </el-cascader>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button class="dialog_confirm" type="primary" @click="confirmMaterial">确定修改</el-button>
                <el-button class="dialog_close" @click="dialogFormVisible3=false">取 消</el-button>
            </div>
        </el-dialog>

        <!-- 改签上课工具 -->
        <el-dialog title="改签上课工具" 
            width='54%'
            :modal=false
            :close-on-click-modal=false
            :visible.sync="dialogFormVisible5">
            <el-form>
                <el-form-item label="上课工具：" :label-width="formLabelWidth">
                    <el-select v-model="changedTool">
                        <el-option 
                            v-for="(ctitem,ct) in form.classTool"
                            :key="ct" :label="ctitem.attriname" :value="ctitem.attriid"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="填写号码：" :label-width="formLabelWidth">
                    <el-input v-model="classtoolAccount" class='divided_2'></el-input>
                </el-form-item>
            </el-form>
        <div slot="footer" class="dialog-footer">
                <el-button class="dialog_confirm" type="primary" @click="confirmChangeTool">确定修改</el-button>
                <el-button class="dialog_close" @click="dialogFormVisible5=false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import base from '../api/base.js'
    import {formatDate} from '../../static/js/date.js'
    import teacherCard from '../components/teacherCard.vue'
    export default {
        components:{
            teacherCard
        },
        data(){
            return{
                changedTool:'',//改签的工具id
                classtoolAccount:'',//用户输入
                tableHeight:window.innerHeight-300,
                loading2:true,
                courseNameTree:[],
                prevurl:'http://file.ehailuo.com',
                courseInfo:{},
                starttime:'',
                endtime:'',
                grouporderid:'',
                ifcourseInfo:false,
                formLabelWidth4:'200px',
                xxSelect:false,
                newcoursewareid:'',
                options:[],
                selectedOptions: [],
                dataArr:[],
                orderInfo:'',
                typeEx:'',
                // 搜索老师
                availableTeacher:[],
                form:{
                    classTool:[],
                    classid:'',
                    coursewareid:'',
                    startdate:'',
                    classtool:'',
                    enddate:'',
                    areaid:'',
                    gender:'',
                    chineselevel:'',
                    changeid:'',//改签 课程记录id
                    ischangeid:true
                },
                chineselevel:[],
                formInline: {
                    teacherid:'',
                    agentid:'',
                    classid:'',
                    start_time:'',
                    end_time:'',
                },
                // form:{

                // },
                changeid:'',
                classid:'',
                align:'center',
                columWidth:148,
                formLabelWidth:'160px',
                experienceData: [],// 课表
                teacherList:[],//老师列表
                schoolList:[],
                classList:[],
                dialogFormVisible1:false,
                dialogFormVisible2:false,
                dialogFormVisible3:false,
                dialogFormVisible4:false,
                dialogFormVisible5:false,
                cancleInfo:'',
                c2show:false,
                c3show:false,
                coursewareid:'',
                 totalCount:0,
                // 分页数据
                currentPage: 1,
                cur_page:1,
                page_size:16,
                //课件联动
                course1:'',
                course2:'',
                course3:'',
                courseid:0,
                course1id:'',
                course2id:'',
                course3id:'',
            }
        },
        methods: {
            //改签上课工具
            changeClassTool(){
                this.getTeacherOpt()
                this.dialogFormVisible5=true
            },
            //确认改签工具
            confirmChangeTool(){
                this.$axios({
                    url: base.baseUrl+"/school/course/set-course-detail",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        changeid:this.grouporderid,
                        newclasstool:this.changedTool,
                        classtoolaccount:this.classtoolAccount 
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==-1){
                        this.alertTip(res.data.msg)
                    }else if(res.data.code==200){
                        this.alertTip('改签成功')
                        this.dialogFormVisible5=false
                    }else if(res.data.code==-2){
                        this.$router.push('/login');
                    }
                });
                
            },
            clearSearch(){
                this.formInline.agentid='' 
                this.formInline.classid='' 
                this.formInline.teacherid='' 
                this.formInline.start_time='' 
                this.formInline.end_time=''
                this.getTableList()
            },
            dialogChange(){
                this.dialogFormVisible2=false
            },
            // 课程详情
            getCourseInfo(gid){
                this.dialogFormVisible4=true
                this.grouporderid=gid 
                this.courseNameTree=[]
                this.$axios({
                    url: base.baseUrl+"/school/course/get-course-info",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        grouporderid:this.grouporderid
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==-1){
                        this.alertTip(res.data.msg)
                    }else if(res.data.code==200){
                        this.courseInfo=res.data.data
                        this.starttime=this.transData(this.courseInfo.classSchedule.starttime)
                        this.endtime=this.transData(this.courseInfo.classSchedule.endtime)
                        this.ifcourseInfo=true
                        for(var index in res.data.data._courseNameTree){
                            this.courseNameTree.push(res.data.data._courseNameTree[index])
                        }
                        this.courseNameTree=this.courseNameTree.join("->");
                        
                    }else if(res.data.code==-2){
                        this.$router.push('/login')
                    }
                })
            },
            transData(time){
                return formatDate(new Date(time * 1000), 'yyyy-MM-dd hh:mm');
            },
            dodown(url){
                window.open(url);
            },
            handleCurrentChange(val) {
                this.loading2=true
                this.cur_page=val;
                this.getTableList();
            },
            // 取消课程
            cancelCourse(cid){
                // this.dialogFormVisible1=true
                this.changeid=this.form.changeid=cid
                this.getCancleInfo()
            },
            getCancleInfo(){
                this.$axios({
                    url: base.baseUrl+"/school/course/get-charge-info",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        changeid:this.changeid,
                        operatetype:2
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==-1){
                        this.alertTip(res.data.msg)
                    }else if(res.data.code==200){
                        this.dialogFormVisible1=true
                        this.cancleInfo=res.data.data; 
                    }else if(res.data.code==-2){
                        this.$router.push('/login');
                    }
                });
            },
            // 确认取消
            confirmCancel(){
                this.$axios({
                    url: base.baseUrl+"/school/course/cancel-course",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        changeid:this.changeid
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==-1){
                        this.alertTip(res.data.msg)
                    }else if(res.data.code==200){
                        this.alertTip('取消成功')
                        this.dialogFormVisible1=false
                        this.getTableList()
                    }else if(res.data.code==-2){
                        this.$router.push('/login');
                    }
                });
            },
            // 改签课程
            changeCourse(cid,sid){
                this.changeid=this.form.changeid=cid
                this.classid=sid
                this.dialogFormVisible2=true
                this.getOrderInfo()
                this.getcourse1()
                this.getTeacherOpt()
            },
            getOrderInfo(){
                this.$axios({
                    url: base.baseUrl+"/school/course/get-order-info",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        orderid:this.changeid
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==200){
                        this.orderInfo=res.data.data;
                        this.form.areaid=res.data.data.areainfo.itemid
                    }else if(res.data.code==-2){
                        this.$router.push('/login')
                    }
                });
            },
            //改签课程 课程联动
            getcourse1(){
                this.$axios({
                    url: base.baseUrl+"/school/course/get-course-list",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        changeid:this.changeid,
                        coursewareid:this.courseid,
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==200){
                        this.course1=res.data.data;
                    }else if(res.data.code==-2){
                        this.$router.push('/login')
                    }
                });
            },
            course1Change(e){
                this.courseid=e;
                this.getCourse2()
            },
            getCourse2(){
                this.$axios({
                    url: base.baseUrl+"/school/course/get-course-list",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        changeid:this.changeid,
                        coursewareid:this.courseid
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==200){
                        if(res.data.data!=null){
                             this.course2=res.data.data;
                             this.c2show=true
                        }
                    }else if(res.data.code==-2){
                        this.$router.push('/login')
                    }
                });
            },
            course2Change(e){
                this.courseid=e;
                this.getCourse3()
            },
            getCourse3(){
                this.$axios({
                    url: base.baseUrl+"/school/course/get-course-list",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        changeid:this.changeid,
                        coursewareid:this.courseid
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==200){
                        if(res.data.data!=null){
                             this.course3=res.data.data;
                             this.c3show=true
                        }
                    }else if(res.data.code==-2){
                        this.$router.push('/login')
                    }
                });
            },       
            // 改签教材
            changeCourseWare(cid){
                this.changeid=this.form.changeid=cid
                this.dialogFormVisible3=true
                this.getCourseList()
            },
            confirmMaterial(){
                this.$axios({
                    url: base.baseUrl+"/school/course/set-course-detail",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        changeid:this.changeid,
                        newcoursewareid:this.newcoursewareid
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==-1){
                        this.alertTip(res.data.msg)
                    }else if(res.data.code==200){
                        this.alertTip('改签成功')
                        this.dialogFormVisible3=false
                    }else if(res.data.code==-2){
                        this.$router.push('/login');
                    }
                });
            },
             // 改签教材课程联动
            getCourseList(){
                this.$axios({
                    url: base.baseUrl+"/school/course/get-course-list",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        changeid:this.changeid,
                        onlycoursewar:1
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==-1){
                        this.alertTip(res.data.msg)
                    }else if(res.data.code==200){
                       this.options=this.dataForm(res.data.data);
                    }else if(res.data.code==-2){
                        this.$router.push('/login')
                    }
                });
            },
            dataForm(arr){
                var dataArr=[];
                arr.map((item ,index)=>{
                    if(item.sublist.length>0){
                        dataArr.push({
                            label: item.title,
                            value: item.id,
                            children:this.dataForm(item.sublist)
                        })
                    }else{
                         dataArr.push({
                            label: item.title,
                            value: item.id,
                        })
                    }
                });
                return dataArr;
            },
            cascaderChange(value) {
                this.newcoursewareid=value[value.length-1]
                // console.log(value[value.length-1]);
            },
            // 按条件搜索列表（不传则为首页列表）
            getTableList(){
                this.$axios({
                    url: base.baseUrl+"/school/class-time-table/get-class-schedule",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        teacherid:this.formInline.teacherid,
                        agentid:this.formInline.agentid,
                        classid:this.formInline.classid,
                        start_time:this.formInline.start_time,
                        end_time:this.formInline.end_time,
                        classtype:1,
                        p:this.cur_page,
                        page_size:this.page_size
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==-1){
                        this.alertTip(res.data.msg)
                    }else if(res.data.code==200){
                        this.experienceData=res.data.data.member_list
                        this.loading2=false
                        this.totalCount=Number(res.data.data.pages.total_count);
                    }else if(res.data.code==-2){
                        this.$router.push('/login');
                    }
                     
                });
            },
            getTeacherList(){
                this.$axios({
                    url: base.baseUrl+"/school/teacher/get-list",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==200){
                        this.teacherList=res.data.data;
                    }else if(res.data.code==-2){
                        this.$router.push('/login');
                    }
                });
            },
            getSchoolList(){
                this.$axios({
                    url: base.baseUrl+"/school/agent/get-agent-list",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==200){
                        this.schoolList=res.data.data;
                    }else if(res.data.code==-2){
                        this.$router.push('/login');
                    }  
                });
            },
            getClassList(){
                this.$axios({
                    url: base.baseUrl+"/school/class/get-class-select",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        classtype:1
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==200){
                        this.classList=res.data.data;
                    }else if(res.data.code==-2){
                        this.$router.push('/login');
                    }
                });
            },
             // 获取老师属性
            getTeacherOpt(){
                 this.$axios({
                    url: base.baseUrl+"/school/course/get-teacher-opt",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==200){
                        this.chineselevel=res.data.data.chineselevel;
                        this.form.classTool=res.data.data.classtool
                    }else if(res.data.code==-2){
                        this.$router.push('/login')
                    }
                });
            },
            searchTeacher(){
                 this.$axios({
                    url: base.baseUrl+"/school/course/experience-teacher-list",
                    method: "POST",
                    header: { 'content-type': 'application/x-www-form-urlencoded' },
                    data:{
                        token:localStorage.token,
                        classid:this.classid,
                        changeid:this.changeid,
                        coursewareid:this.form.coursewareid,
                        startdate:this.form.startdate,
                        classtool:this.form.classtool,
                        enddate:this.form.enddate,
                        // areaid:0,
                        areaid:this.form.areaid,
                        gender:this.form.gender,
                        // chineselevel:0
                        chineselevel:this.form.chineselevel,
                        // p:this.form.p,
                        // page_size:this.form.page_size
                    },
                    transformRequest: [function (data) {
                        let ret = ''
                        for (let it in data) {
                            ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
                        }
                        return ret
                    }],
                }).then(res => {
                    if(res.data.code==-1){
                        this.alertTip(res.data.msg)
                    }else if(res.data.code==200){
                        this.availableTeacher=res.data.data.teacherlist
                        if(this.availableTeacher.length==0){
                            this.alertTip('没有符合条件的老师')
                        }
                    }else if(res.data.code==-2){
                        this.$router.push('/login')
                    }
                });
            },
            alertTip(msg){
                this.$alert(msg, '提示', {
                    confirmButtonText: '确定',
                    // callback: action => {
                    //     this.$message({
                    //         type: 'info',
                    //     });
                    // }
                });
            },
            ifShowxianxia(){
                if(localStorage.roleid==10||localStorage.roleid==12||localStorage.roleid==13||localStorage.roleid==14||localStorage.roleid==15){
                    this.xxSelect=true
                }
            }
        },
        filters:{
            transData(time){
                return formatDate(new Date(time * 1000), 'yyyy-MM-dd hh:mm');
            }
        },
        created(){
            this.getTeacherList()
            this.getSchoolList()
            this.getClassList()
            this.getTableList()
            this.ifShowxianxia()
            // ==============================
            
        }
    }
</script>
<style lang="less" scoped>
    .page_block{
        position: absolute;
        margin-top:12px;
        right: 5%;
    }
    .kejianStyle{
        float:left;margin-right:4px;
    }
    @media screen and (max-width:1700px){
        .el-form--inline{
            width: 1400px;
        }  
    }
    .newWidth{
        width: 220px;
    }
    @media screen and (max-width:1700px){
        .newWidth{
            width: 180px;
        }
        .search_btn{
            width: 80px!important;
        }  
        .reset_btn{
            width: 100px!important;
        }
    }
     @media screen and (max-width:1440px){
        .newWidth{
            width: 130px;
        }
        .reset_btn{
            width:90px!important;
            padding: 0;
        }
    }
    .experienceTable{
        .experience_inputs{
            height: 60px;
            box-sizing: border-box;
            background: #f5f5f5;
            padding-top: 10px;
            display: flex;
            .creatBtn{
                width: 240px;
                cursor: pointer;
            }
            .operate_inputs{
                // padding: 15px 30px;
                height: 70px;
                box-sizing: border-box;
                button{
                    width: 130px;
                    height: 38px;
                    border-radius: 4px;
                    border: none;
                }
                .search_btn{       
                    background-color: #ff5263;
                }
                .reset_btn{
                    background-color: #808080;
                }
            }
        }
    }
</style>

